// pages/equipment/equipment.js
import {
  request
} from '../../request/index.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    washList: [],
    user: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let user = wx.getStorageSync('user');
    let washList = wx.getStorageSync('washList');
    // let washList = typeof wx.getStorageSync('washList')==='string'? JSON.parse(wx.getStorageSync('washList')):wx.getStorageSync('washList');
    this.setData({
      washList,
      user
    });
    console.log(this.data.washList);
  },
  goUserEquip(e) {
    if (Object.keys(this.data.user).length != 0 && this.data.user != '') {
      if (e.currentTarget.dataset.status === 0) {
        // wx.setStorageSync('wash_machine_picture', e.currentTarget.dataset.wash_machine_picture);
        wx.navigateTo({
          url: '../../pages/useEquipment/useEquipment?machineid=' + e.currentTarget.dataset.wash_machine_id
        })
        // request({
        //   url: 'WashMachine/getFunction',
        //   data: {
        //     wash_machine_id: e.currentTarget.dataset.wash_machine_id
        //   },
        // }).then((result) => {
        //   console.log(result);
        //   wx.setStorageSync('functionList', result.data.data.functionList);
        //   wx.navigateTo({
        //     url: '../../pages/useEquipment/useEquipment?machineid=' + e.currentTarget.dataset.wash_machine_id
        //   })
        // });
      } else if(e.currentTarget.dataset.status === 1) {
        wx.showToast({
          title: '机器正在使用',
          icon: 'none',
        })
      }else if(e.currentTarget.dataset.status === 3){
        wx.showToast({
          title: '机器已停用',
          icon: 'none',
        })
      }
    }else{
      wx.showToast({
        title: '请先登录',
        icon:'none'
      })
    }



  },
})